package com.weng.platform.guest.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weng.framework.core.model.ResponseData;
import com.weng.framework.dao.mybatis.model.page.PageModel;
import com.weng.framework.dao.mybatis.service.BaseServiceImpl;
import com.weng.platform.guest.entity.GuestVisitLog;
import com.weng.platform.guest.mapper.GuestVisitLogMapper;
import com.weng.platform.guest.service.IGuestVisitLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Arrays;


/**
 * 访客记录 服务实现类
 *
 * @author weng
 * @date 2021-03-12 14:45:32
 *
 */ 
@Slf4j
@Service
public class GuestVisitLogServiceImpl extends BaseServiceImpl<GuestVisitLogMapper, GuestVisitLog> implements IGuestVisitLogService {
	@Autowired
	private GuestVisitLogMapper guestVisitLogMapper;
	

	/**
	 * 分页查询访客记录
	 * @return
	 */
	@Override
	public IPage<GuestVisitLog> list(Integer pageNo,Integer pageSize, String resourceId) {
		QueryWrapper<GuestVisitLog> qw = new QueryWrapper<>();
		qw.eq("resource_id", resourceId);
		IPage<GuestVisitLog> page = new PageModel<>(pageNo,pageSize);
		return guestVisitLogMapper.selectPage(page,qw);
	}


	/**
	 * 获取单个访客记录
	 * @param id
	 * @return
	 */
	@Override
	public GuestVisitLog getById(Serializable id) {
		return super.getById(id);
	}

	/**
	 * 新增单个访客记录
	 * @param guestVisitLog
	 * @return
	 */
	@Override
	public GuestVisitLog add(GuestVisitLog guestVisitLog)  {
		
		guestVisitLogMapper.insert(guestVisitLog);
		return guestVisitLog;
	}

	/**
	 * 更新单个访客记录
	 * @param guestVisitLog
	 * @return
	 * @
	 */
	@Override
	public int update(GuestVisitLog guestVisitLog)  {
		
		return guestVisitLogMapper.updateById(guestVisitLog);

	}


	@Override
	public ResponseData removeByIds(String ids) {
		String[] guestVisitLogIds = ids.split(",");
		boolean flag = this.removeByIds(Arrays.asList(guestVisitLogIds));
		if (flag) {
			return ResponseData.success();
		} else {
			return ResponseData.success();
		}
	}

}
